import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/Login";
import LibraryManager from "@/views/LibraryManager";
import BooksDisplay from "@/views/BooksDisplay";
import PrivateMsg from "@/views/PrivateMsg";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/libraryManager',
    name: '图书管理',
    component: LibraryManager,
    redirect:'/booksDisplay',
    children:[
      {
        path:'/booksDisplay',
        name:'图书列表',
        component:BooksDisplay,
      },
      {
        path:'/privateMsg',
        name:'个人信息',
        component:PrivateMsg,
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

router.beforeEach((to, from, next) => {
  const code=localStorage.getItem("isLogin")
  if (to.name!="login" && code!=1){
    next({path:'/'})
  }else{
    next();
  }
})
